<{include file="OA/cooperation/header.tpl"}>
	<section id="spread_one" class="column">
		
        <{if $alert_message}>
		<h4 class="alert_info"><{$alert_message}></h4>
        <{/if}>
		

		<article class="module width_3_quarter" >
		<header>
			<h3 class="tabs_involved " style="width:500px">添加新的合作包 <a href="../developer/add">新增开发者</a> &nbsp;<a href="../developer/add_contact">新增联系人</a></h3>
		</header>
		<form action='add_submit' method='post' id="add_apk">
		<div class="tab_container">
			<div id="tab1" class="tab_content">
			<table class="tablesorter apk-edit" cellspacing="0" cellpadding="0"> 
			<tbody> 
				<tr> 
   					<td><label class="l01">合作包包名</label><input type="text" class="package_name" name="packagename" size="24"> 
					</td> 
					<td>
						<span class="package_icon_url"></span>
						<span class="apk_name"></span>
						<input type="hidden" class="input_apk_name" name="apk_name" value="<{$apk.name}>">
					</td> 
				</tr> 
				<tr> 
					<td>
                       <label class="l01">支付方式</label>
                        <select name='pay_type'>
                            <{foreach from="$pay_type" item=v}>
                                 <option value ="<{$v.id}>"><{$v.name}></option>
                            <{/foreach}>
                        </select>
                    </td>
					<td>
						<label class="l01" id="corporation">合作公司</label>
                        <select name='corporation' id="corpor">
                                <option value ="000" selected>请选择开发者</option>
                            <{foreach from="$devs" item=v}>
                                 <option value ="<{$v.id}>"><{$v.name}></option>
                            <{/foreach}>
                        </select>
                    </td>
				</tr> 
				 <tr>
					<td>
                        <label class="l01">cp分成比例</label><input type="text" name="ratio" size="4">%
                    </td>
                    <td>
						<label class="l01">税费比例</label><input type="text" name="cost_ratio" size="4">%
                    </td>
                </tr>
				 <tr>
					<td>
                        <label class="l01">结算联系人</label>
                        <select name="payment_uid" class="payment_contacts">
							 <{foreach from="$payments" item=v}>
                                 <option value ="<{$v.id}>" <{if $v.id == $apk.payment_uid}> selected <{/if}>><{$v.name}></option>
                            <{/foreach}>
                        </select>
                    </td>
					<td>
                        <label class="l01">商务联系人</label>
                        <select name="business_uid" class="buisness_contacts">
							 <{foreach from="$business" item=v}>
                                 <option value ="<{$v.id}>" <{if $v.id == $apk.business_uid}> selected <{/if}>><{$v.name}></option>
                            <{/foreach}>
                        </select>
                    </td>
                </tr>
				<tr>
                    <td>
                        <label class="l01">合作开始时间</label><input type="text" value="<{$start_date}>" id="date1" name='start_time' />
                    </td>
                    <td>
                        <label class="l01">合作结束时间</label><input type="text" value="2099/12/31" id="date2" name='end_time' />
                    </td> 
				</tr> 
				<tr>
					<td colspan="2" style="text-align:center">
						<input type="submit" class="bulid_action fw spread_submit" value="提交">
					</td>
				</tr>
			</tbody> 
			</table>
			</div><!-- end of #tab1 -->
		</div><!-- end of .tab_container -->
		</form>	
		</article><!-- end of content manager article -->
		<div class="clear"></div>
	</section>
	<script>
		$('#add_apk').submit(function() {
			// form validation.
			if ($('.input_apk_name').val() == 'error_pkg')
            {
                alert('包名不合法');
                return false;
            }
			if ($('#corpor').val()=='000')
			{
				alert('请选择一个添加过的开发者');
				return false;
			}	
			return confirm('是否确定添加此合作包？');
		});
		$('.package_name').blur(function () {
			var package_name  = $('.package_name').val();	
            $.get('apk_info?package_name=' + package_name, {} ,function (data) {
					if(data.name){
						$('.apk_name').html(data.name);
						$('.input_apk_name').val(data.name);
						$('.package_icon_url').html('<img src="'+data.iconUrl+'">');
						flag = false;
					}else{
						$('.apk_name').html('包名不合法');
						$('.input_apk_name').val('error_pkg');
					}
            } , 'json');
		});
		$('#corpor').change(function () {
			var corp_id  = $('#corpor').val();	
			var url = '../developer/get_contacts/'+ corp_id ;
            $.get(url, {} ,function (data) {
					if(data){
						var html = ''
						for (var i = 0; i < data.length; ++i)
                   		{
                       	 var id = data[i].id;
                       	 var name = data[i].name;

                       	 html += '<option value='+ id +'>'+ name +'</option>';
                    	}
                    	$('.buisness_contacts').html(html);
						$('.payment_contacts').html(html);
					}else {
						$('.buisness_contacts').html('');
						$('.payment_contacts').html('');
					}
            } , 'json');
		});
	</script>
<{include file="OA/cooperation/footer.tpl"}>
